﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApp001.Domain.Entity;

namespace WebApp001.Domain
{
    public class DbInintializeHelper
    {
        public static void Initilizer()
        {
            using (var db=new Admin4000DbContext())
            {
                var dbExist=db.Database.EnsureCreated();

                var tempBrand = db.Brands.Any();

                if (!dbExist)
                {
                    var bran = new Brand
                    {
                        BrandName = "XiaoMi",
                        Description = "中国的一个产品"
                    };

                    Brand brand = null;
                    db.Brands.Add(brand);

                    db.SaveChanges();

                    db.Products.AddRange(new Product[]
                        {
                        new Product
                        {
                            ProductName = "小米9 魅蓝色",
                            ShorDesc = "小米8",
                            FullDesc = "小米7",
                            BrandId = brand .Id
                        },
                        new Product
                        {
                            ProductName = "小米9 X 玫瑰色",
                            ShorDesc = "滴滴滴",
                            FullDesc = "这是一个花花",
                            BrandId = brand .Id
                        }
                        });
                    db.SaveChanges();
                }
              
            }
        }
    }
}
